package com.example.rwq_test.jdkProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 实现InvocationHandler接口
 *
 * @author renweiqiang
 * @version 1.0.0
 * @createTime 2023/9/13
 */
public class MyInvocationHandler implements InvocationHandler {
    private Object target;

    public MyInvocationHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("Before method execution");
        Class<?> aClass = proxy.getClass();
        System.out.println(aClass.getName());
        Object result = method.invoke(target, args);
        System.out.println("After method execution");
        return result;
    }
}
